package com.liudadan.controller;

import com.liudadan.pojo.Schedule;
import com.liudadan.service.ScheduleService;
import com.liudadan.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@CrossOrigin
@RestController
@RequestMapping("/schedule")
public class ScheduleController {

    @Autowired
    private ScheduleService service;

    @GetMapping
    public R findAll(){
        //1. 形参列表接收参数
        //2. 调用业务逻辑
        List<Schedule> list = service.getAll();
        R ok = R.ok(list);
        return ok;
    }

    @DeleteMapping("{id}")
    public R delete(@PathVariable Integer id){
        service.removeById(id);
        return R.ok(null);
    }

    @PostMapping
    public R save(@RequestBody Schedule schedule){
        service.saveSchedule(schedule);
        return R.ok(null);
    }

    @PutMapping
    public R update(@RequestBody Schedule schedule){
        service.updateSchedule(schedule);
        return R.ok(null);
    }
}
